'''
=======================
limber.ui.dialogs.utils
=======================

This module contains utility functions for dialogs.
'''

__all__ = (
    'DIALOGS',
    'register_dialog',
    'unregister_dialog',
    'get_dialog')



DIALOGS = {}

def register_dialog(dialog, name):
    '''Registers a dialog to LimberEditor.'''

    if name in DIALOGS:
        raise ValueError('The dialog %r was already registered.' % name)
    DIALOGS[name] = dialog

def unregister_dialog(name):
    '''Unregisters the given dialog.'''

    if name not in DIALOGS:
        raise ValueError('There is %r dialog registered.' % name)
    del DIALOGS[name]

def get_dialog(name):
    '''Return the dialog with the given *name*.'''

    return DIALOGS[name]